#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
struct Pos{
    int x,t;
    Pos(){};
    Pos(int xx,int tt):x(xx),t(tt){};
};
Pos start,goal;
queue<Pos> q;
int visited[100005];
bool inRange(int x){
    return x>=0&&x<=100000;
}
int main(){
    int N,K;
    cin>>N>>K;
    memset(visited,0,sizeof(visited));
    start=Pos(N,0);
    goal=Pos(K,-1);
    visited[start.x]=1;
    q.push(start);
    Pos p;
    while(!q.empty()){
        p=q.front();
        if(p.x==goal.x){
            cout<<p.t<<endl;
            break;
        }
        q.pop();

        if(inRange(p.x-1)&&visited[p.x-1]==0){
            q.push(Pos(p.x-1,p.t+1));
            visited[p.x-1]=1;
        }
        if(inRange(p.x+1)&&visited[p.x+1]==0){
            q.push(Pos(p.x+1,p.t+1));
            visited[p.x+1]=1;
        }
        if(inRange(p.x*2)&&visited[p.x*2]==0){
            q.push(Pos(p.x*2,p.t+1));
            visited[p.x-1]=1;
        }                
    }
    
    return 0;
}